//
//  HXLWeatherCollectionViewCell.m
//  On The Load
//
//  Created by 晓琳 on 15/11/16.
//  Copyright © 2015年 @@叶一闽. All rights reserved.
//

#import "HXLWeatherCollectionViewCell.h"
#import "WeekModel.h"


@interface HXLWeatherCollectionViewCell ()

@property (nonatomic,strong)WeekModel *seven;
@property (nonatomic,strong)UILabel *week;
@property (nonatomic,strong)UILabel *weather;
@property (nonatomic,strong)UILabel *temp_high;
@property (nonatomic,strong)UILabel *temp_low;
@property (nonatomic,strong)UILabel *days;
@property (nonatomic,strong)UILabel *wind;
@property (nonatomic,strong)UILabel *winp;
@property (nonatomic, strong) UIImageView *backView;

@property (nonatomic,strong)UIView *dotView1;
@property (nonatomic,strong)UIView *dotView2;

@end

@implementation HXLWeatherCollectionViewCell

- (instancetype) initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void) createSubviews {
    
    self.backView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height)];
//    self.backView.backgroundColor = [UIColor colorWithRed:0.176 green:0.323 blue:0.317 alpha:1.000];
    self.backView.alpha = 0.8;
    [self.contentView addSubview:self.backView];
    
    self.week = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50 * SCALEW, 30 * SCALEH)];
    //    self.week.backgroundColor = [UIColor redColor];
    self.week.font = [UIFont systemFontOfSize:14 * SCALEW];
    [self.week setTextAlignment:NSTextAlignmentCenter];
    self.week.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.week];
    
    self.weather = [[UILabel alloc] initWithFrame:CGRectMake(0, 40 * SCALEH, 50 * SCALEW, 30 * SCALEH)];
    self.weather.font = [UIFont systemFontOfSize:10 * SCALEW];
    //    self.weather.backgroundColor = [UIColor redColor];
    [self.weather setTextAlignment:NSTextAlignmentCenter];
    self.weather.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.weather];
    self.weather.numberOfLines = 0;
    
    self.temp_high = [[UILabel alloc] initWithFrame:CGRectMake(0, 140 * SCALEH, 50 * SCALEW, 30 * SCALEH)];
    //    self.temp_high.backgroundColor = [UIColor redColor];
    self.temp_high.textColor = [UIColor whiteColor];
    [self.temp_high setTextAlignment:NSTextAlignmentCenter];
    self.temp_high.font = [UIFont systemFontOfSize:14 * SCALEW];
    [self.contentView  addSubview:self.temp_high];
    
    self.temp_low = [[UILabel alloc] initWithFrame:CGRectMake(0, 260* SCALEH, 50 * SCALEW, 30 * SCALEH)];
    //    self.temp_low.backgroundColor = [UIColor redColor];
    self.temp_low.textColor = [UIColor whiteColor];
    [self.temp_low setTextAlignment:NSTextAlignmentCenter];
    self.temp_low.font = [UIFont systemFontOfSize:14 * SCALEW];
    [self.contentView addSubview:self.temp_low];
    
    self.days = [[UILabel alloc] initWithFrame:CGRectMake(0, 300 * SCALEH, 50 * SCALEW, 40 * SCALEH)];
    //    self.days.backgroundColor = [UIColor redColor];
    self.days.textColor = [UIColor whiteColor];
    [self.days setTextAlignment:NSTextAlignmentCenter];
    self.days.font = [UIFont systemFontOfSize:14 * SCALEW];
    [self.contentView addSubview:self.days];
    
    self.wind = [[UILabel alloc] initWithFrame:CGRectMake(0, 340 * SCALEH, 50 * SCALEW, 30 * SCALEH)];
    //    self.wind.backgroundColor = [UIColor redColor];
    self.wind.textColor = [UIColor whiteColor];
    [self.wind setTextAlignment:NSTextAlignmentCenter];
    self.wind.font = [UIFont systemFontOfSize:10 * SCALEW];
    [self.contentView addSubview:self.wind];
    self.wind.numberOfLines = 0;
    
    self.winp = [[UILabel alloc] initWithFrame:CGRectMake(0, 370 * SCALEH, 50 * SCALEW, 30 * SCALEH)];
    //    self.winp.backgroundColor = [UIColor redColor];
    self.winp.textColor = [UIColor whiteColor];
    [self.winp setTextAlignment:NSTextAlignmentCenter];
    self.winp.font = [UIFont systemFontOfSize:14 * SCALEW];
    [self.contentView addSubview:self.winp];
    self.winp.numberOfLines = 0;
    
    
    self.dotView1 = [[UIView alloc] init];
    [self.contentView addSubview:self.dotView1];
    self.dotView1.layer.cornerRadius = 3;
    self.dotView1.backgroundColor = [UIColor whiteColor];
    
    
    self.dotView2 = [[UIView alloc] init];
    [self.contentView addSubview:self.dotView2];
    self.dotView2.layer.cornerRadius = 3;
    self.dotView2.backgroundColor = [UIColor whiteColor];
}


- (void)setWeekModel:(WeekModel *)weekModel {
    _weekModel  = weekModel;
    
    
    self.week.text = self.weekModel.week;
    self.weather.text = self.weekModel.weather;
    self.temp_high.text = self.weekModel.temp_high;
    self.temp_low.text = self.weekModel.temp_low;
    self.days.text = [self.weekModel.days substringFromIndex:5];
    self.wind.text = self.weekModel.wind;
    self.winp.text = self.weekModel.winp;
    
    if ([self.weekModel.weather containsString:@"雨"]) {
        self.backView.image= [UIImage imageNamed:@"rain"];
        //        [self createNowWeatherBackView];
    }else if ([self.weekModel.weather containsString:@"晴"]){
        self.backView.image = [UIImage imageNamed:@"sun"];
        //        [self createNowWeatherBackView];
    }else if ([self.weekModel.weather containsString:@"云"]){
        self.backView.image= [UIImage imageNamed:@"yun"];
        //        [self createNowWeatherBackView];
    }else if ([self.weekModel.weather containsString:@"雪"]){
        self.backView.image = [UIImage imageNamed:@"snow"];
        //        [self createNowWeatherBackView];
    }
    else if ([self.weekModel.weather containsString:@"阴"]){
        self.backView.image = [UIImage imageNamed:@"yin"];
        //        [self createNowWeatherBackView];
    }else if ([self.weekModel.weather containsString:@"霾"]){
        self.backView.image = [UIImage imageNamed:@"mai"];
        //        [self createNowWeatherBackView];
    }
    else
    {
        self.backView.image = [UIImage imageNamed:@"back1.png"];
        //        [self createNowWeatherBackView];
    }

    CGFloat high = [self.weekModel.temp_high floatValue];
    self.dotView1.frame = CGRectMake(0, 0, 6 * SCALEW, 6 * SCALEW);
    self.dotView1.center = CGPointMake(25 * SCALEW, 170 * SCALEH - high * 2.25);
    
    CGFloat low = [self.weekModel.temp_low floatValue];
    self.dotView2.frame = CGRectMake(0, 0, 6 * SCALEW, 6 * SCALEW);
    self.dotView2.center = CGPointMake(25 * SCALEW, 240 * SCALEH - low * 2.25);
    
    self.temp_high.center = CGPointMake(25 * SCALEW, 155 * SCALEH - high * 2.25);
    self.temp_low.center = CGPointMake(25 * SCALEW, 255 * SCALEH - low * 2.25);
    
}

@end
